package edu.uw.tcss360.group6.gui.MainCards;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import edu.uw.tcss360.group6.gui.GUI;
import edu.uw.tcss360.group6.model.Contestant;
import edu.uw.tcss360.group6.model.*;


/**
 * Created with IntelliJ IDEA.
 * edu.uw.tcss360.group6.model.User: Lemtzas
 * Date: 2/20/13
 * Time: 9:46 PM
 * To change this template use File | Settings | File Templates.
 */
@SuppressWarnings("serial")
public class ContestantSplashPanel extends MainCard {
	private JButton view_weaving_draft_1;
	private JButton view_weaving_draft_2;
	private JButton view_weaving_draft_3;
	int counter1 = 0;
	int counter2 = 0;
	int counter3 = 0;
    public ContestantSplashPanel() {
        super();
        this.add(new JLabel("Contestant Splash Page"));
        counter1 = 0;
        counter2 = 0;
    	counter3 = 0;
        JButton submit = new JButton("Submit Weave");
        submit.addActionListener(new ActionListener() {
        	public void actionPerformed(ActionEvent evt) {
        		GUI.instance().my_main_panel.setCard("edu.uw.tcss360.group6.model.Entry"); //bill
        	}
        });
        this.add(submit,BoxLayout.Y_AXIS);
        JButton view_drafts = new JButton("View Weaving drafts");
        view_drafts.addActionListener(new ActionListener() {
        	public void actionPerformed(ActionEvent evt) {
        		GUI.instance().my_main_panel.setCard("weaving-draft-selection"); 
        		 final Contestant temp = (Contestant) GUI.instance().currentUser;
        	        switch(temp.getEntries().length){
        	        	case 1: 
        	        		counter1++;
        	        		view_weaving_draft_1 = new JButton("View Weave 1");
        	        		view_weaving_draft_1.addActionListener(new ActionListener(){
        	        			public void actionPerformed(final ActionEvent the_event)
        	        			{
        	        				GUI.instance().my_side_panel.datacardpanel.getContestantCard().disableSubmission();
        	        		  
        	        				Entry entry = temp.getEntries()[0];
        	        				GUI.instance().my_main_panel.getWeavingPanel().setWeavingDraft(entry.getWeavingDraft());
        	        				GUI.instance().my_main_panel.setCard("weaving-draft");
        	        				GUI.instance().setFlag(false);
        	        				GUI.instance().setdraftFlag1(true);
        	        			}
        	        		});
        	        		if(counter1 <= 1)
        	        			GUI.instance().my_main_panel.addToWeavingSelectionPanel(view_weaving_draft_1);
        	        		break;
        	        	case 2:
        	        		counter2++;
        	        		view_weaving_draft_1 = new JButton("View Weave 1");
        	        		view_weaving_draft_1.addActionListener(new ActionListener(){
        	        			public void actionPerformed(final ActionEvent the_event)
        	        			{
        	        				GUI.instance().my_side_panel.datacardpanel.getContestantCard().disableSubmission();
        	        		  
        	        				Entry entry = temp.getEntries()[0];
        	        				GUI.instance().my_main_panel.getWeavingPanel().setWeavingDraft(entry.getWeavingDraft());
        	        				GUI.instance().my_main_panel.setCard("weaving-draft");
        	        				GUI.instance().setFlag(false);
        	        				GUI.instance().setdraftFlag1(true);
        	        			
        	        			}
        	        		});
        	            
        	        		
        	        		view_weaving_draft_2 = new JButton("View Weave 2");
        	        		view_weaving_draft_2.addActionListener(new ActionListener(){
        	        			public void actionPerformed(final ActionEvent the_event)
        	        			{
        	        				GUI.instance().my_side_panel.datacardpanel.getContestantCard().disableSubmission();
        	        		  
        	        				Entry entry = temp.getEntries()[1];
        	        				GUI.instance().my_main_panel.getWeavingPanel().setWeavingDraft(entry.getWeavingDraft());
        	        				GUI.instance().my_main_panel.setCard("weaving-draft");
        	        				GUI.instance().setFlag(false);
        	        				GUI.instance().setdraftFlag2(true);
        	        			}
        	        		});
        	        		if(counter2 <= 1)
        	        		{
        	        			GUI.instance().my_main_panel.addToWeavingSelectionPanel(view_weaving_draft_1);
            	        		GUI.instance().my_main_panel.addToWeavingSelectionPanel(view_weaving_draft_2);
        	        		}
        	        		
        	        		break;
        	        	case 3:
        	        		counter3++;
        	        		view_weaving_draft_1 = new JButton("View Weave 1");
        	        		view_weaving_draft_1.addActionListener(new ActionListener(){
        	        			public void actionPerformed(final ActionEvent the_event)
        	        			{
        	        				GUI.instance().my_side_panel.datacardpanel.getContestantCard().disableSubmission();
        	        		  
        	        				Entry entry = temp.getEntries()[0];
        	        				GUI.instance().my_main_panel.getWeavingPanel().setWeavingDraft(entry.getWeavingDraft());
        	        				GUI.instance().my_main_panel.setCard("weaving-draft");
        	        				GUI.instance().setFlag(false);
        	        				GUI.instance().setdraftFlag1(true);
        	        			}
        	        		});
        	            
        	        		view_weaving_draft_2 = new JButton("View Weave 2");
        	        		view_weaving_draft_2.addActionListener(new ActionListener(){
        	        			public void actionPerformed(final ActionEvent the_event)
        	        			{
        	        				GUI.instance().my_side_panel.datacardpanel.getContestantCard().disableSubmission();
        	        		  
        	        				Entry entry = temp.getEntries()[1];
        	        				GUI.instance().my_main_panel.getWeavingPanel().setWeavingDraft(entry.getWeavingDraft());
        	        				GUI.instance().my_main_panel.setCard("weaving-draft");
        	        				GUI.instance().setFlag(false);
        	        				GUI.instance().setdraftFlag2(true);
        	        			}
        	        		});
        	        		
        	        		view_weaving_draft_3 = new JButton("View Weave 3");
        	        		view_weaving_draft_3.addActionListener(new ActionListener(){
        	        			public void actionPerformed(final ActionEvent the_event)
        	        			{
        	        				GUI.instance().my_side_panel.datacardpanel.getContestantCard().disableSubmission();
        	        		  
        	        				Entry entry = temp.getEntries()[2];
        	        				GUI.instance().my_main_panel.getWeavingPanel().setWeavingDraft(entry.getWeavingDraft());
        	        				GUI.instance().my_main_panel.setCard("weaving-draft");
        	        				GUI.instance().setFlag(false);
        	        				GUI.instance().setdraftFlag3(true);
        	        			}
        	        		});
        	        		if(counter3 <= 1)
        	        		{
        	        			GUI.instance().my_main_panel.addToWeavingSelectionPanel(view_weaving_draft_1);
            	        		GUI.instance().my_main_panel.addToWeavingSelectionPanel(view_weaving_draft_2);
            	        		GUI.instance().my_main_panel.addToWeavingSelectionPanel(view_weaving_draft_3);
        	        		}
        	        		
        	        		break;
        	        
        	        }
        	        
        		
        	}
        });
        this.add(view_drafts, BoxLayout.Y_AXIS);
       
       
    }
   
   
}
